package com.zeek.car90s.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zeek.car90s.Constants;
import com.zeek.car90s.R;
import com.zeek.car90s.util.ViewHolder;

import java.util.ArrayList;

import static com.zeek.car90s.R.id.tv_map_item;

/**
 * Created by Administrator on 2016/4/7.
 */
public class MapAdapter extends BaseAdapter {

    private ArrayList<Integer> datas;
    private Context context;

    public MapAdapter(ArrayList<Integer> datas, Context context) {
        this.datas = datas;
        this.context = context;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final LinearLayout ll;
        if (convertView == null) {
            ll = (LinearLayout) LayoutInflater.from(this.context).inflate(R.layout.map_gridview_item, null);
        } else {
            ll = (LinearLayout) convertView;
        }

        TextView tvMapItem = ViewHolder.get(ll, tv_map_item);
        int level = datas.get(position);
        if (level > Constants.MAX_UNLOCK_LEVEL) {
            tvMapItem.setText("");
            tvMapItem.setBackgroundResource(R.drawable.map_lock);
        } else {
            tvMapItem.setText(level + 1 + "");
            tvMapItem.setBackgroundResource(R.drawable.map_unlock);
        }


        return ll;
    }
}
